<style lang="less">
@import '../../../assets/style/renyuanxuanze.less';
.pop_up{
	.van-popup {
		width: 85%;
		padding: 10px;
		max-height: 80%;
		min-height: 18%;
		text-align: left;
		.list_box{
			font-size:14px;
			border-bottom:1px dotted #ddd;
			.title {
				display: inline-block;
				width: 30%;
			}
		}
	}
}
</style>

<template>
	<mxq-router-layout>
		<div class="search towerList">
			<Head slot="header" @headerClick="headerClick($event)">
				<div slot="headerTitle">
					<van-search v-model.trim="value" placeholder="请输入杆塔名称"  @input="onSearch"/>
				</div>
				<div slot="headerRight">
					<i class="iconfont icon-shouye"/>
					<!--<van-icon class="home" name="home"/>-->
				</div>
			</Head>
			<ganta-List
				:gantaList="gtLists"
				:picUrlLeft="picUrlLeft"
				@clickList="clickList">
				<template slot="titles1" slot-scope="item">
					<span class="iconBox">
						<img
							:src="picUrlRight"
							alt=""
							class="iconRight">
						<em class="iconText">接受任务</em>
					</span>
				</template>
			</ganta-List>
			<div class="tower_text" v-show="isShow" v-if="gtLists.length==0">
				没有找到"{{value}}"的搜索结果
			</div>
			<!-- 隐患 -->
			<div class="pop_up">
				<van-popup v-model="yin">
					<div>
						<div v-for="(item,index) in hiddenData" :key="index" class="list_box">
							<p>
								<span class="title">分类：</span>
								<span class="name">{{item.NAME}} ({{item.TYPE?'隐':"1"}})</span>
							</p>
							<p>
								<span class="title">发现时间：</span>
								<span class="name">{{item.TIME}}</span>
							</p>
							
							<p>
								<span class="title">等级：</span>
								<span class="name">{{item.LEVEL_}}</span>
							</p>
							<p>
								<span class="title">状态：</span>
								<span class="name">{{item.STATUS}}</span>
							</p>
							<p>
								<span  class="title">责任人：</span>
								<span class="name">{{item.USERNAME ? true : ''}}</span>
							</p>
						</div>
					</div>
				</van-popup>
			</div>

			<!-- 缺陷 -->
			<div class="pop_up">
				<van-popup v-model="que">
					<span class="pop_txt" style="font-size:16px;">
						缺陷
					</span>
					<div>
						<div v-for="(item,index) in defectsData" :key="index" class="list_box">
							<p>
								<span  class="title">分类：</span>
								<span>{{item.NAME}} ({{item.TYPE ? "0" : '缺'}})</span>
							</p>
							<p>
								<span  class="title">发现时间：</span>
								<span class="name">{{item.TIME}}</span>
							</p>
							
							<p>
								<span class="title">等级：</span>
								<span class="name">{{item.LEVEL_}}</span>
							</p>
							<p>
								<span class="title">状态：</span>
								<span class="name">{{item.STATUS}}</span>
							</p>
							<p>
								<span class="title">责任人：</span>
								<span class="name">{{item.USERNAME ? true: ''}}</span>
							</p>
						</div>
					</div>
				</van-popup>
			</div>

			<div class="pop_up">
				<van-popup v-model="yinAndQue">
					<div class="con_box">
						<div v-for="(item,index) in hiddenDefectsData" :key="index" class="list_box">
							<p>
								<span class="title">分类：</span>
								<span class="name">{{item.NAME}}({{item.TYPE==0 ? "缺" : '隐'}})</span>
							</p>
							<p>
								<span class="title">发现时间：</span>
								<span class="name">{{item.TIME}}</span>
							</p>
							<p>
								<span class="title">等级：</span>
								<span class="name">{{item.LEVEL_}}</span>
							</p>
							<p>
								<span class="title">状态：</span>
								<span class="name">{{item.STATUS}}</span>
							</p>
							<p>
								<span class="title">责任人：</span>
								<span class="name">{{item.USERNAME?true:''}}</span>
							</p>
						</div>
					</div>
				</van-popup>
			</div>
		</div>
	</mxq-router-layout>
</template>

<script>
import Head from '../../../components/head'
import GantaList from '../../../components/ganta-list'
import IconGT from '../../../assets/img/changguixunshi/icon_gt.png'
import IconQD from '../../../assets/img/changguixunshi/icon_rw.png'
import { callData } from '../../../axios/axios'
import { getSession } from '../../../libs/cache'
import {
	Icon,
	Search,
	Toast,
	Popup
} from 'vant';

export default {
	name:'gantaxunshi',
    components: {
		Head,
		GantaList,
		[Icon.name]: Icon,
		[Search.name]: Search,
		[Popup.name]: Popup,
		[Toast.name]: Toast
	},
	data() {
		return {
			iconText:"",
			towerId:'',//杆塔id
			cname: 'iconRight',
			value:'',
			gtLists:[],
			picUrlLeft: IconGT,
			picUrlRight: IconQD,
			listImg:[IconGT,IconQD],
			isShow:false,
			yin:false,					//隐
			hiddenData: [],				//隐患数据
			listType: [],				//隐患详情Key
			detailShow: [],				//数据集合
			que:false,					//缺
			defectsData: [],			//缺陷数据
			hiddenDefectsData:[],	//隐患和缺陷数据
			yinAndQue: false,			//隐和缺
		}
	},
	mounted() {
		this.getListGT();//获取杆塔数 
    },
    methods: {
		// 头部两侧按钮点击事件
		headerClick(e){
			let query = {}
			this.$router.push({
				name:'index',
				query: query
			})
		},
		//点击列表
		clickList(e) {
			var userMeg = JSON.parse(getSession('userMeg'));
			let query = {
				cmTowerId:e.data.CM_TOWER_ID,
				towerTaskId:e.data.TOWER_TASK_ID,
				jdUserId:e.data.JD_USER_ID,
				punchtype:e.data.PUNCHTYPE,
				lineId:e.data.CM_LINE_ID,
				lineName:e.data.LINE_NAME,
				towerId: e.data.TOWER_ID,
				towerName:e.data.TOWER_NAME,
				taskId :e.data.JX_TASK_ID,
				lineTowerId :e.data.CM_LINE_TOWER_ID,
				gantaStatus:e.data.JX_TASK_STATUS,
				taskStatus: this.$route.query.taskStatus,
				towerStatus: 1,
				index:this.$route.query.index
			}
			//隐患缺陷提示
			if(e.todo == -1){
				var _this = this;
				if(e.data.IS_YH=="1" && e.data.IS_QX=="0"){ //隐
					callData('/accountServer/YhDefectCheck/findyhDefectTaskTowerList', 'get', {
						towerId:e.data.TOWER_ID
					}).then(res => {
						if(res.success){
							_this.yin = true;
							var resHidden = res.data;
							_this.hiddenData = resHidden;
						}
					})
				}
				else if(e.data.IS_QX=="1" && e.data.IS_YH=="0"){//缺
					callData('/accountServer/YhDefectCheck/findyhDefectTaskTowerList', 'get', {
						towerId:e.data.TOWER_ID
					}).then(res => {
						if(res.success){
							_this.que = true;
							var resDefects = res.data;
							_this.defectsData = resDefects;
						}
					})
				}
				else if(e.data.IS_YH=="1" && e.data.IS_QX=="1"){//隐和缺
					callData('/accountServer/YhDefectCheck/findyhDefectTaskTowerList', 'get', {
						towerId:e.data.TOWER_ID
					}).then(res => {
						if(res.success){
							_this.yinAndQue = true;
							var hiddendefects = res.data;
							_this.hiddenDefectsData = hiddendefects;
						}
					})
				}else {}
			}//todo=1表示查看，=0表示接受任务按钮
			else if(e.todo == 0 && e.data.JD_USER_ID == null){//开始接单
				var params ={
					acceptTask:1,//1表示接单
					towerTaskId : e.data.TOWER_TASK_ID
				}
				
				callData('/jxtaskServer/JxTowerTask/updateJdUser', 'put', params).then(res => {
					if(res.success){
						query.name = 'xljx_allowPhotos'
						this.$router.push({
							name:'xljx_allowPhotos',
							query: query
						})
					}
					Toast(res.data);
				})
			}else if(e.data.TS_XS_TASK_STATUS==2) { //已完成的任务人可查看
				query.name = 'tsxs_allowPhotos'
				query.towerStatus=2
				this.$router.push({
					name:'tsxs_allowPhotos',
					query: query
				})
			}else if(e.todo == 1 && e.data.JD_USER_ID == null){//没有接单，可以点击列表进行查看,不操作
				
				this.$router.push({
					name:'xljx_noPhotos',
					query: {
						cmTowerId:e.data.CM_TOWER_ID,
						towerTaskId:e.data.TOWER_TASK_ID,
						jdUserId:e.data.JD_USER_ID,
						punchtype:e.data.PUNCHTYPE,
						lineId:e.data.CM_LINE_ID,
						lineName:e.data.LINE_NAME,
						towerId: e.data.TOWER_ID,
						towerName:e.data.TOWER_NAME,
						taskId :e.data.JX_TASK_ID,
						lineTowerId :e.data.CM_LINE_TOWER_ID,
						gantaStatus:e.data.JX_TASK_STATUS,
						taskStatus: this.$route.query.taskStatus,
						towerStatus: e.data.JX_TASK_STATUS,
						index:this.$route.query.index
					}
				})
				
			}else if(e.todo == 1 && e.data.JD_USER_ID == userMeg.id){//接过单之后(进行中)，还可以点击列表进去，此时只可以进入自己的任务
				query.name = 'xljx_allowPhotos'
				this.$router.push({
					name:'xljx_allowPhotos',
					query: query
				})
			}else if((e.todo == 1 )){
				if (e.data.JD_USER_ID != userMeg.id) {
					Toast('非本人不可进行操作');
					return;
				}
			}
		},
		//获取杆塔数据列表
		getListGT(){
			var params ={
				page :0,
				size : 800,
				taskId : this.$route.query.taskId
			}
			callData('/jxtaskServer/JxTowerTask/findJxTaskLine', 'get', params).then(res => {
				this.initData(res)
			})
		},
		//杆塔名模糊查询
		onSearch(){
			callData('/jxtaskServer/JxTowerTask/findJxTaskLine', 'get', {
				page :0,
				size : 800,
				taskId : this.$route.query.taskId,
				towerName:this.value
			}).then(res => {
				this.initData(res)
				this.isShow = true;
			})
		},
		initData(res){
			if (!res || !res.data || !res.data.content) {
				return;
			}
			var gtData = res.data.content;
			gtData.forEach((item,index) => {
				item.textName = item.LINE_NAME_SHORT + ' - ' + item.TOWER_NAME + '杆塔';
				this.towerId =  res.data.content.TOWER_TASK_ID;
				item.alarm=item.IS_YH==1?'have':'';
				item.que=item.IS_QX==1?'have':'';
				if(JSON.parse(getSession('userMeg')).id != item.JD_USER_ID){
					item.cname="btn_statusgray"
				}
				// 状态判断
				if (item.JX_TASK_STATUS == 0) {
					item.status = item.JX_TASK_STATUS;
					this.iconText = '接受任务';
					item.statusName = '未巡视';
					item.cname="btn_status";
				}else if (item.JX_TASK_STATUS == 1) {
					item.statusName = '进行中';
					item.cname="btn_status1";
					if(JSON.parse(getSession('userMeg')).id != item.JD_USER_ID){
						item.cname="btn_statusgray"
					}
				}else if (item.JX_TASK_STATUS == 2){
					item.statusName = '已完成';
					item.status = item.JX_TASK_STATUS;
					item.cname="btn_status2";
					if(JSON.parse(getSession('userMeg')).id != item.JD_USER_ID){
						item.cname="btn_statusgray"
					}
				}
			});
			this.gtLists = gtData;
		}
	}
}
</script>
